package com.moniteach.utils;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.moniteach.bo.Group;
import com.moniteach.bo.Predmet;

public abstract class MyList<T> {
	ArrayList<T> objects = new ArrayList<T>();

	public ArrayList<T> getResult(final String response, final String arrayName) {
		JSONArray array = null;
		Predmet predmet = null;
		Group group = null;
		try {
			array = new JSONArray(response);
			int i = 0;
			while (true) {
				// JSONObject objectarray = array.getJSONObject(i);
				if ("groups".equals(arrayName)) {
					group = new Group(array.getJSONObject(i));
					objects.add((T) group);
				}
				if ("predmets".equals(arrayName)) {
					predmet = new Predmet(array.getJSONObject(i));
					objects.add((T) predmet);
				}
				i++;
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} finally {
			return objects;
		}
	}
}
